package sd.settemmezzo.util;

import java.io.Serializable;

import sd.settemmezzo.player.state.LocalState;

public class Message implements Serializable {
	private static final long serialVersionUID = -2698159679417334910L;
	
	private int sender;
	private int type;
	private Object message;
	
	private int access;
	private int maxaccess;
	
	public Message(int type, Object message) {
		this(type, message, Integer.MAX_VALUE);
	}
	
	public Message(int type, Object message, int maxaccess) {
		this.sender = LocalState.getInstance().getId();
		this.type = type;
		this.message = message;
		this.access = 0;
		this.maxaccess = maxaccess;
	}
	
	public Object getObject() { 
		if (access < maxaccess) {
			access++;
			return this.message;
		} else return null;
	}
	
	public int getSender() { 
		return this.sender; 
	}
	
	public int getType() { 
		return this.type; 
	}
	
	public boolean isValid() {
		return (access < maxaccess);
	}
	
	public final static int GS_UPDATE = 0;
	public final static int CRASH_DETECTED = 1;
	public final static int CRASH_ON_PING = 2;
	public final static int FINE_MANO = 3;
}
